"""
AI分析记录模型
"""

from sqlalchemy import Column, Integer, String, Text, DateTime, ForeignKey, JSON, Float
from sqlalchemy.sql import func
from sqlalchemy.orm import relationship
from ..core.database import Base


class AnalysisRecord(Base):
    """AI分析记录模型"""
    __tablename__ = "analysis_records"

    id = Column(Integer, primary_key=True, index=True)
    analysis_type = Column(String(50), nullable=False, index=True)  # requirement_analysis, test_generation
    input_content = Column(Text)  # 输入内容
    output_content = Column(Text)  # 输出内容
    file_name = Column(String(255))  # 原始文件名
    file_type = Column(String(50))  # 文件类型
    file_size = Column(Integer)  # 文件大小
    processing_time = Column(Float)  # 处理时间
    
    status = Column(String(20), default="success")  # success, failed, pending
    error_message = Column(Text)  # 错误信息
    
    # AI相关信息
    ai_model = Column(String(50))  # 使用的AI模型
    tokens_used = Column(Integer)  # 使用的token数量
    
    # 外键
    user_id = Column(Integer, ForeignKey("users.id"))
    requirement_id = Column(Integer, ForeignKey("requirements.id"))
    
    # 时间戳
    created_at = Column(DateTime(timezone=True), server_default=func.now())
    updated_at = Column(DateTime(timezone=True), onupdate=func.now())
    
    # 关系
    user = relationship("User", back_populates="analysis_records")
    requirement = relationship("Requirement", back_populates="analysis_records") 